<?php
/**
 * AJAX Handler for Contrib: List - List all contributors on the project, and return array up the ajax call to the page calling.
 * 
 * I have made sure Libdebug is silent in AJAX. This is because it can intefere with the HTML/Javascript as Libdebug Appends after </html>.
 * If you have a problem and need to debug comment $_LIBDEBUG->silence(); (the framework must also be in debugging mode for this to work)
 */

    $_ECLIPSEMDE = array();
    
    // Disable Templating System
    $_ECLIPSEMDE['TEMPLATING'] = false;
    require_once('../../SiteIncludes.GLOBAL.php');
    
    // Tell libdebug to never print out error information - overrides debugging flags in fwork
    $_LIBDEBUG->silence();
    
    if(EclipseMDE::runningOnMod_Rewrite() === false) {
	// Security Guard, Do Not Let This be accessed by any other means than mod_rewrite
	header("HTTP/1.1 400 Bad Request");
	die($nok_caller);
    }
    
    // Ensure all variables needed are set
    if(isset($_LOGGEDINUSER) === true && $_LOGGEDINUSER !== false && isset($gVAR['alias']) !== false) {
	try {
	    $Project =& $ProjectStash->get($gVAR['alias']);
	    if($Project->userCanEdit($_LOGGEDINUSER->get_userid()) === true) {
		$Users = $Project->getNoneLeaderMaintainers();
		$js_usr = ''; $js_ids = '';
		$js_i = 0;
		foreach($Users as $key => $value) {
		    $User =& $UserStash->get($value);
		    $js_usr .= "names[$js_i] = '{$User->get_username()}';\n";
		    $js_ids .= "ids[$js_i] = '{$User->get_userid()}';\n";
		    $js_i++;
		}
		echo <<<EOT
		    <!DOCTYPE html>
			<html>
			    <head><title></title></head>
			    <body>
				<script type="text/javascript">
				    var names = new Array();
				    var ids = new Array();
				    {$js_usr}
				    {$js_ids}
				    parent.UserContribEDJX.update(names, ids);
				</script>
			    </body>
			</html>
EOT;
	    } else {
		throw new InvalidProjectException();
	    }
	} catch(InvalidProjectException $e) {
	    header("HTTP/1.1 400 Bad Request");
	    die($nok_caller);
	}
    } else {
	header("HTTP/1.1 400 Bad Request");
	die($nok_caller);
    }